import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import './assets/css/global.css';
import axios from 'axios'
import './assets/img/font/iconfont.css'
import './assets/img/tools/iconfont.css'
import 'default-passive-events'
import * as echarts from 'echarts'
import drag from './common/drag.js';
/*import changecolor from './common/changecolor.js';
import pm10 from './common/pm10.js';*/
import JsonExcel from "vue-json-excel";
Vue.component('download-excel',JsonExcel)
Vue.prototype.$http1 = axios;
const service = axios.create({
   baseURL:'/api',
   withCredentials:true
})
service.interceptors.request.use(config=>{
  if(config.baseURL!='/iserver'){
    config.headers.token=window.sessionStorage.getItem('token');
  }else {
    config.headers.token=window.sessionStorage.getItem('iserverToken');
  }
  return config
})
Vue.prototype.$http = service;

const service2 = axios.create({
  baseURL:'/iserver',
  withCredentials:true
})
service2.interceptors.request.use(config=>{
  if(config.baseURL!='/iserver'){
    config.headers.token=window.sessionStorage.getItem('token');
  }else {
    config.headers.token=window.sessionStorage.getItem('iserverToken');
  }

  return config
})
Vue.prototype.$http2 = service2;

const service3 = axios.create({
  baseURL:'/back',
  withCredentials:true
})
service3.interceptors.request.use(config=>{
  if(config.baseURL!='/iserver'){
    config.headers.token=window.sessionStorage.getItem('token');
  }else {
    config.headers.token=window.sessionStorage.getItem('iserverToken');
  }
  return config
})
Vue.prototype.$http3 = service3;


const service4 = axios.create({
  baseURL:'/bup',
  withCredentials:true
})
service4.interceptors.request.use(config=>{
  if(config.baseURL!='/iserver'){
    config.headers.token=window.sessionStorage.getItem('token');
  }else {
    config.headers.token=window.sessionStorage.getItem('iserverToken');
  }
  return config
})
Vue.prototype.$http4 = service4;
const service5 = axios.create({
  baseURL:'/phone',
  withCredentials:true
})
service5.interceptors.request.use(config=>{
     console.log(config)
    //config.headers.token='5j1znBVAsnSf5xQyNQyq'
    return config
})
Vue.prototype.$http5 = service5;
const service11 = axios.create({
  baseURL:'/phone',
  withCredentials:true
})
service11.interceptors.request.use(config=>{
  console.log(config)
  //config.headers.token='5j1znBVAsnSf5xQyNQyq'
  return config
})
Vue.prototype.$http11 = service11;

const service132 = axios.create({
  baseURL:'/doLogin',
  withCredentials:true
})
service132.interceptors.request.use(config=>{
  console.log(config)
  return config
})
Vue.prototype.$http132 = service132;
/*const service6 = axios.create({
  baseURL:'/tdt',
  withCredentials:true
})
service6.interceptors.request.use(config=>{
  //config.headers.token='5j1znBVAsnSf5xQyNQyq'
  return config
})
Vue.prototype.$http6 = service6;*/

Vue.config.productionTip = false

/* 路由发生变化修改页面title */
/*router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})*/

//控制按钮显隐
Vue.directive('has', {
  bind: function (el, binding) {
    if (!Vue.prototype.$_has(binding.value)) {
      el.style.display = 'none'
    }
  }
})
// 权限检查方法
Vue.prototype.$_has = function (value) {
  let isExist = false
  let role= JSON.parse(window.sessionStorage.getItem("btnData"));
  if (role.indexOf(value)!==-1 ) {
    isExist = true
  }
  return isExist
}

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
